home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 3_0 / DOUBLEDE / UTILITIE.C < prev    next >
C/C++ Source or Header  |  1988-05-29  |  3KB  |  117 lines

  1. #include "MacTypes.h"
  2. #include "Quickdraw.h"
  3. #include "WindowMgr.h"
  4. #include "MemoryMgr.h"
  5.  
  6. /********************************************************************
  7.  
  8.         centerwindow(wind,r)
  9.         WindowPtr    wind;
  10.         Rect        *r;
  11.     
  12.     centers the window referenced by the WindowPtr: wind within
  13.     the Rect referenced by the Rect* r.  To center a window in
  14.     the Macintosh screen, (or primary screen if using a Mac II),
  15.     call...
  16.         centerwindow(theWindow,&screenBits.bounds);
  17.  
  18. *******************************************************************/
  19. centerwindow(wind,r)
  20. WindowPtr    wind;
  21. Rect        *r;
  22. {
  23.     Rect    r2;
  24.     int        windW,windH;
  25.     int        rectW,rectH;
  26.     
  27.     r2 = wind->portRect;
  28.         
  29.     windW = r2.right-r2.left;
  30.     windH = r2.bottom-r2.top;
  31.     
  32.     rectW = r->right - r->left;
  33.     rectH = r->bottom - r->top;
  34.     
  35.     MoveWindow    (wind,
  36.                 r->left+(rectW-windW)/2,
  37.                 r->top+(rectH-windH)/2,
  38.                 FALSE);
  39. }
  40.  
  41. /********************************************************************
  42.  
  43.         centerrect(r1,r2)
  44.         Rect        *r1,*r2;
  45.     
  46.     centers the rectangle referenced by the Rect* r1 within
  47.     the Rect referenced by the Rect* r2.  To center the Rect
  48.     innerRect within the Rect outerRect, call...
  49.     
  50.         centerrect(&innerRect,&outerRect);
  51.  
  52. *******************************************************************/
  53. centerrect(r1,r2)
  54. Rect    *r1,*r2;
  55. {
  56.     OffsetRect    (r1,
  57.                 ((r2->right-r2->left)-(r1->right-r1->left))/2-r1->left,
  58.                 ((r2->bottom-r2->top)-(r1->bottom-r1->top))/2-r1->top);
  59. }
  60.  
  61.  
  62. /********************************************************************
  63.  
  64.             Boolean TrackMyRect(aPoint,r1,rad1,rad2)
  65.             Point    aPoint;
  66.             Rect    *r1;
  67.             int        rad1,rad2;
  68.         
  69.     TrackMyRect() treats the Rect referenced by *r1 much like
  70.     the TrackControl(ControlHandle) of the Control Manager. The
  71.     point passed by aPoint should be the local coordinates of the
  72.     mouse down location in the window in which the Rect resides,
  73.     and should initially be called with the mouse location inside
  74.     of the Rect.
  75.     
  76.     rad1 and rad2 are radii for rounded rects, pass 0 in these
  77.     values if the Rect is not rounded.
  78.     
  79.     Sample Code Fragment....
  80.     
  81.     Point        thePoint;
  82.     Rect        myRect;
  83.     Boolean        rectSelected;
  84.     
  85.     thePoint = theEvent.where;
  86.     GlobalToLocal(&thePoint);
  87.     if (PtInRect(thePoint,&myRect))
  88.         rectSelected = TrackMyRect(thePoint,&myRect,0,0);
  89.     
  90.         
  91. *******************************************************************/
  92. Boolean TrackMyRect(aPoint,r1,rad1,rad2)
  93. Point    aPoint;
  94. Rect    *r1;
  95. int        rad1,rad2;
  96. {
  97.     Boolean        returnVal = TRUE;
  98.     
  99.     InvertRoundRect(r1,rad1,rad2);
  100.     do    {
  101.         GetMouse(&aPoint);
  102.         if (PtInRect(aPoint,r1) != returnVal)
  103.             {
  104.             returnVal = !returnVal;
  105.             InvertRoundRect(r1,rad1,rad2);
  106.             SystemTask();
  107.             }
  108.     } while (StillDown());
  109.     GetMouse(&aPoint);
  110.     if (PtInRect(aPoint,r1)){
  111.         InvertRoundRect(r1,rad1,rad2);
  112.         return(TRUE);
  113.     }
  114.     else
  115.         return(FALSE);
  116. }
  117.